﻿using Kinlo.MESDocking;
using NPOI.OpenXmlFormats.Spreadsheet;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UIWindows.GlobalStatics;
using UIWindows.Models.Devices;
using XingLucifer.Devices;

namespace UIWindows.Services.PLC_MESHelper
{
    /// <summary>
    /// 清扫码队列2
    /// </summary>
    public class InitBarcode2Handler : HelperBase
    {
        PLCBase InjMachine { get; set; }

        MESWinderOutRecordAddRec _mesWinderOutRecord { get; set; }
        public InitBarcode2Handler(
                     DeviceInteractiveaddressStatic deviceInteractiveaddressStatic,
            DeviceClientModel deviceModel,
            TemporaryStatic temporaryStatic,
            ParameterStatic parameterStatic,
            DeviceConfigStatic deviceConfigStatic,
            SystemConfigStatic systemConfigStatic,
             HomeStatic homeStatic,
             Action<string, string, string, string, string, long, DateTime, string, string, string, string> log, Action<string, string, string> dialog
            ) : base(deviceInteractiveaddressStatic, deviceModel, temporaryStatic, parameterStatic, deviceConfigStatic, systemConfigStatic, homeStatic, log, dialog)
        {
            InjMachine = deviceModel.PLC;
            _mesWinderOutRecord = new MESWinderOutRecordAddRec(_log, _dialog);
        }
        public override Task Handle()
        {
            //KL21050011Machine InjMachine = null;
            try
            {
               RunLog($"【清扫码队列2】");
                //var dicts = ctx.Container.Get<ConcurrentDictionary<string, object>>();
                //InjMachine = (KL21050011Machine)dicts.GetOrAdd("InjMachine", InjMachine);
                //var data = ctx.Container.Get<PlateData>();
                //data.ScanQueueList.Clear();
                //data.PlateQueueList.Clear();
            }
            catch (Exception ex)
            {
                RunLog($"【清扫码队列2】发生异常:{ex}");
            }
            finally
            {
                var r1 = InjMachine.Write("DM1005", new short[] { 0 });
                RunLog($"【清扫码队列2】写结果信号{0} {r1} {(r1 ? "成功" : "失败")}");
            }
            return base.Handle();
        }
    }
     
}
